package thesis.javaclass;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


public class ThesisServer {
	
	private static final int PORT = 1343;
	private static ServerSocket serverSocket ;
	
	private static Socket client = null;
	private static BufferedReader input = null;
	
	public static void main(String[] agrs) {
		try {
			serverSocket = new ServerSocket(PORT);
		}catch(IOException ioex) {
			System.out.println("Unable to set up port ....");
			System.exit(1);
		}
		do {
			try {
				client = serverSocket.accept();
			
			input = new BufferedReader(new InputStreamReader(client.getInputStream()));
			String message = "";
			do {
				message = input.readLine();
				System.out.println("ThesisServer nhan duoc: "+message);
			}while(!message.equals("CLOSE"));
			client.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}while(true);
	}
}
